package com.ggh.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ggh.dao.UserRecordMapper;
import com.ggh.entity.RoomBeanP;
import com.ggh.entity.RoomRecord;
import com.ggh.entity.UserBean;
import com.ggh.entity.UserRecord;
import com.ggh.service.UserRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author ： jsq
 * @date ：2019/10/13 22:24
 * @description : 战绩
 * @path : com.ggh.service.impl.RoomRecordServiceImpl
 * @modifiedBy ：
 */
@Service
public class UserRecordServiceImpl extends ServiceImpl<UserRecordMapper, UserRecord> implements UserRecordService {
    /**
    * @description :循环存入相关房间用户的战绩
    * @param roomBeanP 
    * @return: boolean
    * @date : 2019/10/14 15:15
    * @author : jj
    * @throws
    */

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addList(RoomBeanP roomBeanP) {
            /* 循环所有用户，存入战绩信息*/
        List<UserBean> game_userlist = roomBeanP.getGame_userlist();
        for (int i = 0; i < game_userlist.size(); i++) {
            UserBean us = game_userlist.get(i);
                if (us.getReady_state() == 4&&us.getLog_lat() == -1) {
                    continue;
                }
                UserRecord userRecord=new UserRecord();
                    userRecord.setUserid(us.getUserid());
                    userRecord.setRoomno(roomBeanP.getRoomno());
                    userRecord.setTimeStr(new Date());
                    userRecord.setMoneyStr(us.getSyfen());
                    if (roomBeanP.getGame_type()==3||roomBeanP.getGame_type()==4){
                        userRecord.setTypeStr(2);
                    }else if (roomBeanP.getGame_type()==5||roomBeanP.getGame_type()==6||roomBeanP.getGame_type()==7){
                        userRecord.setTypeStr(3);
                    }else {
                        userRecord.setTypeStr(roomBeanP.getGame_type());
                    }
                    userRecord.insert();
            }
        return true;
    }
}
